<?php
mb_internal_encoding("UTF-8");
//header("Content-type: text/html; charset=utf-8"); 
//include_once('func.php');
$key = 'zhongshiyou';
$secret = 'eyJ0eXBlIjoiMjQiLCJjYXRlZ29yeV9pZCI6IjEzOCJ9';
$params = array(
    'name' => '江明',
    'mobile' => '18600291074',
    'id_num' => '420683199110282131',
    'time' => '1493715258',
    'key' => $key,
);
$sign = getSignature($params, $secret);
$str = "id_num=420683199110282137key=zhongshiyoumobile=18518488785name=江永time=1493715258eyJ0eXBlIjoiMjQiLCJjYXRlZ29yeV9pZCI6IjEzOCJ9";
var_dump($sign);


 function getSignature($params, $secret = '123456')
 {
    $str = '';  //待签名字符串
    //先将参数以其参数名的字典序升序进行排序
    ksort($params);
    //遍历排序后的参数数组中的每一个key/value对
    foreach ($params as $k => $v) {
        //为key/value对生成一个key=value格式的字符串，并拼接到待签名字符串后面
        $str .= "$k=$v";
    }
    //将签名密钥拼接到签名字符串最后面
    $str .= $secret;
    //var_dump($str);
    //通过md5算法为签名字符串生成一个md5签名，该签名就是我们要追加的sign参数值
    return md5($str);
 }
